package com.aplink.generic.util.convertcount;

import com.aplink.generic.constant.ControlType;
import com.aplink.generic.pojo.GenericObject;
import com.aplink.generic.pojo.controlspec.ControlSpec;

import java.util.ArrayList;

public class GenericCounter {

    public static int countSubmitButton( ArrayList<ControlSpec> controlSpecList ) {

        int count = 0;

        for ( ControlSpec aControlSpec : controlSpecList ) {
            if ( ControlType.Button == aControlSpec.getControlType() ) {
                count++;
            }
        }

        return count;
    }

    public static String getSumValueFromAnAttribute(
            ArrayList<GenericObject> genericObjectList, String attributeId ) {

        double totalValue = 0;
        for ( GenericObject genericObject : genericObjectList ) {
            double value = 0;
            try {
                value = Double.valueOf( genericObject
                        .getContentFromAttributeName( attributeId ) );
            } catch ( final Exception e ) {
                value = 0;
            }
            totalValue += value;
        }
        return String.valueOf( totalValue );
    }
}
